<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../include.jsp"%>


<div class="modal-header">
   <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
   <h4 class="modal-title" id="layoutModalLabel"><strong>部门信息</strong></h4>
</div>
<div class="modal-body">
  <form method="post" class="form-horizontal" action="${ctx }/admin/admin/organizations/${method}">
	<div class="form-group">
		 <label class="col-sm-2 control-label" for="orgName">组织名称</label>
		 <div class="col-sm-10 ">
			<input type="text" class="form-control" id="orgName"  name="orgName" placeholder="部门名称" value="${row.orgName}">
		 </div>
	</div>
	<div class="form-group">
		 <label class="col-sm-2 control-label" for="description">说明</label>
		 <div class="col-sm-10 ">
			<input type="text" class="form-control" id="description"  name="description" placeholder="说明" value="${row.description}">
		 </div>
	</div>
	<div class="form-group">
		 <label class="col-sm-2 control-label" for="shortName">简称</label>
		 <div class="col-sm-10 ">
			<input type="text" class="form-control" id="shortName"  name="shortName" placeholder="简称" value="${row.shortName}">
		 </div>
	</div>
	<div class="form-group">
		 <label class="col-sm-2 control-label" for="jianpin">简拼</label>
		 <div class="col-sm-10 ">
			<input type="text" class="form-control" id="jianpin"  name="jianpin" placeholder="简拼" value="${row.orgType}">
		 </div>
	</div>
	<div class="form-group">
		 <label class="col-sm-2 control-label" for="orgType">部门类型</label>
		 <div class="radio col-sm-10 ">
		 	<xhz:utils var="orgTypes" type="org_types">
		 	<c:if test="${(not empty orgTypes)}">
		 		<c:forEach items="${orgTypes.adminDictionaryList }" var="dictionary">
	 			  <label>
					    <input type="radio" name="orgType" <c:if test="${row.orgType eq dictionary.dictionaryId }"> checked="checked" </c:if> value="${dictionary.dictionaryId }" >${dictionary.dictionaryLabel }
				  </label>
		 		</c:forEach>
		 	</c:if>
		 	</xhz:utils>
		 </div>
	</div>
	<div class="form-group">
		 <label class="col-sm-2 control-label" for="sort">排序</label>
		 <div class="col-sm-10 ">
			<input type="text" class="form-control" id="sort"  name="sort" placeholder="排序" value="${row.sort }">
		 </div>
	</div>
	<div class="form-group">
		 <label class="col-sm-2 control-label" for="status">状态</label>
		 <div class="col-sm-10 ">
			<input type="text" class="form-control" id="status"  name="status" placeholder="状态" value="${row.status }">
		 </div>
	</div>
	
	<div class="form-group">
		 <label class="col-sm-2 control-label" for="companyType">公司类型  </label>
		 
		 <div class="radio col-sm-10 ">
		 	<xhz:utils var="companyTypes" type="company_types">
		 	<c:if test="${(not empty companyTypes)}">
		 		<c:forEach items="${companyTypes.adminDictionaryList }" var="dictionary">
	 			  <label>
					    <input type="radio" name="companyType" <c:if test="${row.companyType eq dictionary.dictionaryId }"> checked="checked" </c:if> value="${dictionary.dictionaryId }" >${dictionary.dictionaryLabel }
				  </label>
		 		</c:forEach>
		 	</c:if>
		 	</xhz:utils>
		 </div>
	</div>
	<div class="form-group hide">
		<!-- 隐藏区域 -->
		<input type="text" class="form-control" id="parentId"  name="parentId" placeholder="父节点Id" value="${row.parentId }">
	 	<input type="text" class="form-control" id="parentCode"  name="parentCode" placeholder="父节点部门机构代码" value="${row.parentCode }">
		<input type="text" class="form-control" id="orgId"  name="orgId" placeholder="部门机构代码" value="${row.orgId }">
	</div>
 </form>
</div>
<div class="modal-footer">
  <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
  <button type="button" class="btn btn-primary" id="submitForm">提交</button>
</div>
<script>

$(function(){
	
	$('.form-horizontal').validate({
	    errorElement : 'span',
	    errorClass : 'help-block',
	    focusInvalid : true,
	    rules : {
					orgCode:{maxlength:[10000],required:true},
					orgName:{maxlength:[100],required:true},
					description:{maxlength:[100],required:true},
					shortName:{maxlength:[50],required:true},
					jianpin:{maxlength:[50],required:true},
					orgType:{maxlength:[11],required:true},
					sort:{maxlength:[11],required:true},
					status:{maxlength:[4],required:true},
					companyType:{maxlength:[4],required:true},
					parentId:{maxlength:[11],required:true}
	    },
	    messages : {
					orgCode:{maxlength:'输入长度最多是10000的字符串(汉字算一个字符).',required:'该项为必填项.'},
					orgName:{maxlength:'输入长度最多是100的字符串(汉字算一个字符).',required:'该项为必填项.'},
					description:{maxlength:'输入长度最多是100的字符串(汉字算一个字符).',required:'该项为必填项.'},
					shortName:{maxlength:'输入长度最多是50的字符串(汉字算一个字符).',required:'该项为必填项.'},
					jianpin:{maxlength:'输入长度最多是50的字符串(汉字算一个字符).',required:'该项为必填项.'},
					orgType:{maxlength:'输入长度最多是11的字符串(汉字算一个字符).',required:'该项为必填项.'},
					sort:{maxlength:'输入长度最多是11的字符串(汉字算一个字符).',required:'该项为必填项.'},
					status:{maxlength:'输入长度最多是4的字符串(汉字算一个字符).',required:'该项为必填项.'},
					companyType:{maxlength:'输入长度最多是4的字符串(汉字算一个字符).',required:'该项为必填项.'},
					parentId:{maxlength:'输入长度最多是11的字符串(汉字算一个字符).',required:'该项为必填项.'}
	    },
	
	    highlight : function(element) {
	        $(element).closest('.form-group').addClass('has-error');
	    },
	
	    success : function(label) {
	        label.closest('.form-group').removeClass('has-error');
	        label.remove();
	    },
	
	    errorPlacement : function(error, element) {
	        element.parent('div').append(error);
	    }
	});
	
	
	$('#submitForm').on('click' ,function(){
		$submit = $(this) ;
		
		var valid = true ;
		XHZ.formPost('.form-horizontal',$submit ,valid ,function(data){
			var msg = "添加成功" ;
			$('#layoutModal').modal('hide') ;
			if(data.code != 1){
				$('.actionBar .glyphicon-refresh').click() ;
			}else{
				msg = data.message ;
			}
			$submit.removeClass('disabled') ;
			$('#alertModal .modal-body').html(msg) ;
			$('#alertModal').modal({
				backdrop: 'static' ,
				show: true
			}) ;
			
			refreshNode() ;
		}) ;
	}) ;

	 function refreshNode() {
	    	var zTree = $.fn.zTree.getZTreeObj(tree) ;
	    	var type = "refresh" ;
	    	var silent = true ;
	    	var nodes = zTree.getSelectedNodes();
	    	if (nodes.length == 0) {
	    		var msg = "<h4><span class='danger'>要选择一个节点才能刷新哦!</span></h4>" ;
				$('#alertModal .modal-body').html(msg) ;
				$('#alertModal').modal({
					backdrop: 'static' ,
					show: true
				}) ;
				return false ;
	    	}
	    	for (var i=0, l=nodes.length; i<l; i++) {
	    		zTree.reAsyncChildNodes(nodes[i], type, silent);
	    		if (!silent) zTree.selectNode(nodes[i]);
	    	} ;
	    }
});

</script>